#ifndef XGE_GRAPHICS_G_TEXTURE_H_
#define XGE_GRAPHICS_G_TEXTURE_H_
#include "xge_common_config.h"
#include "g_common.h"
#include "g_colors.h"
#include "xsmart_ptr.h"
#include "xallocator.h"
#include "xtype.h"




namespace xge{
namespace graphics{
  using xge::Allocator;
  using xge::Rect;

  // This texture interface is simply a simple wrapper base for
  // the specific texture interface.
  class Texture : public Allocator {
  public:
    size_t image_width() const {
      return image_width_;
    }
    size_t image_height() const {
      return image_height_;
    }
    size_t width() const {
      return vram_width_;
    }
    size_t height() const {
      return vram_height_;
    }
    // Lock the internal texture buffer will make the 
    // internal texture pixel buffer been download from
    // the GPU local VRAM , so it is an expansive operation
    // it will return a Colors class which makes you 
    // access the internal pixel data.
    // the usage should be specified , for it relates to the
    // performance . In addition , the rectangle of this 
    // pixel buffer should be specified as well , if you 
    // keep default the Whole Area of the rectangle will be
    // locked .
    virtual ColorStream Lock(
       LockOption usage , 
       const Rect& rect ) =0;
    // Every call of the locking operation will force you
    // to call the Unlock function corresponding to that
    // Lock operation .
    virtual bool Unlock() =0;
  protected:
    // Texture internal Ctor.This Ctor will manually call
    // by the derived class directly .
    Texture( size_t image_width , size_t image_height , size_t vram_width , size_t vram_height ) :
           image_width_(image_width) , 
           image_height_(image_height),
           vram_width_(vram_width),
           vram_height_(vram_height) {}

    ~Texture(){}
  private:
    size_t image_width_ , image_height_ ;
    size_t vram_width_ , vram_height_ ;

  };

  struct TextureDestructor {
    static void Destroy( Texture* texture ) ;
  };
  // The texture pointer do not need to be thread safe
  typedef xge::xge_internal
    ::SharedPtr< Texture , TextureDestructor , xge::xge_internal::CommonOperationPolicy > TexturePtr;

}//namespace graphics 
}//namespace xge
#endif// XGE_GRAPHICS_G_TEXTURE_H_